package jp.sinmetal.trainer.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Version;

import org.seasar.framework.beans.util.Beans;


/**
 * 大会ログエンティティ
 * @author sin
 *
 */
@Entity
@Table(name="convention_log")
public class ConventionLog extends AbstractEntity {

	/**
	 * 通常状態
	 * @author sin
	 */
	public static Integer STATE_NORMAL = 0;
	/**
	 * 勝利状態
	 * @author sin
	 */
	public static Integer STATE_WIN = 1;
	/**
	 * パス状態
	 * @author sin
	 */
	public static Integer STATE_PASS = 2;

    /**
     * 大会ログID
     * @author sin
     */
    @Id
    @GeneratedValue
    @Column(name="convention_log_id")
    public Integer conventionLogId;

    /**
     * 大会ID
     * @author sin
     */
    @Column(name="convention_id")
    public Integer conventionId;

    /**
     * 大会参加者ID1st
     * @author sin
     */
    @Column(name="convention_member_id1st")
    public Integer conventionMemberId1st;

    /**
     * 大会参加者ID2nd
     * @author sin
     */
    @Column(name="convention_member_id2nd")
    public Integer conventionMemberId2nd;

    /**
     * 勝利者ID
     * @author sin
     */
    @Column(name="win_convention_member_id")
    public Integer winConventionMemberId;

    /**
     * 状態
     * @author sin
     */
    @Column(name="convention_log_state")
    public Integer conventionLogState;

    /**
     * 登録日時
     * @author sin
     */
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="entry_date")
    public Date entryDate;

    /**
     * 更新日時
     * @author sin
     */
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="update_date")
    public Date updateDate;

    /**
     * バージョン
     * @author sin
     */
    @Version
    public Long version;

    //----------- s2jdbc連結定義 ----------

    /**
     * 大会参加者1stエンティティ
     * @author sin
     */
    @ManyToOne
    @JoinColumn(name="convention_member_id1st", referencedColumnName="convention_member_id")
    public ConventionMember conventionMember1st;

    /**
     * 大会参加者2ndエンティティ
     * @author sin
     */
    @ManyToOne
    @JoinColumn(name="convention_member_id2nd", referencedColumnName="convention_member_id")
    public ConventionMember conventionMember2nd;

    /**
     * 勝利者エンティティ
     * @author sin
     */
    @ManyToOne
    @JoinColumn(name="win_convention_member_id", referencedColumnName="convention_member_id")
    public ConventionMember winConventionMember;

    /**
     * 大会エンティティ
     * @author si
     */
    @ManyToOne
    @JoinColumn(name="convention_id", referencedColumnName="convention_id")
    public Convention convention;

    //----------- -----------

    /**
     * ConventionLogのインスタンスを返す
     * @author sin
     *
     * @param form
     * @return
     */
    public static ConventionLog getInstance(Object form) {
    	return Beans.createAndCopy(ConventionLog.class, form).dateConverter(DATE_FORMAT).execute();
    }

}